package com.itheima.tliaswebmanagement.controller;

import com.itheima.tliaswebmanagement.pojo.common.PageResult;
import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.itheima.tliaswebmanagement.pojo.dto.ClazzPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.entity.Clazz;
import com.itheima.tliaswebmanagement.service.ClazzService;
import com.sun.net.httpserver.Authenticator;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ClazzMapper
 * @Author ziguan ling
 * @Date 2025--01--03
 */
@RequestMapping("/clazzs")
@RestController
@Slf4j
public class ClazzController {
    @Autowired
    ClazzService clazzService;


    @GetMapping
    public Result page(ClazzPageQueryDTO clazzPageQueryDTO) {
        log.info("查询分页班级列表:{}", clazzPageQueryDTO);
        PageResult<Clazz> pageResult = clazzService.page(clazzPageQueryDTO);

        return Result.success(pageResult);

    }


    @PostMapping
    public  Result add(@RequestBody Clazz clazz){
        log.info("添加班级: {}", clazz);


        clazzService.addClazz(clazz);

        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("根据id查询:{}",id);

        Clazz clazz = clazzService.queryById(id);

        return Result.success(clazz);
    }

    @PutMapping
    public Result  update(@RequestBody Clazz clazz){
        log.info("修改班级信息:{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result  deleteById(@PathVariable Integer id){
        log.info("删除班级{}",id);
        clazzService.del(id);
        return Result.success();
    }

    @GetMapping("list")
    public Result queryAll() {
        log.info("查询所有班级");

        List<Clazz> clazz = clazzService.queryAll_s();

        return Result.success(clazz);
    }

}

































